package com.tanhua.controller;

import com.tanhua.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/backstage")
@CrossOrigin
public class AdminHoutaiController {
    @Autowired
    public AdminService adminService;


    @PostMapping(name = "登录", value = "/users/login")
    public ResponseEntity login(@RequestBody Map<String, String> map) throws Exception {
        String username = map.get("username");
        String password = map.get("password");
        return adminService.backstageLogin(username, password);
    }

    @GetMapping("/userinfo/{username}")
    public ResponseEntity getInfo(@PathVariable("username") String username) {
        return adminService.getInfo(username);
    }

    /**
     * 发送短信
     *
     * @param phone
     * @return
     * @throws Exception
     */
    @GetMapping("/sendSMS")
    public ResponseEntity sendSMS(String phone) throws Exception {
        return adminService.sendSMS(phone);

    }

    /**
     * 通过短信登录或注册（免密登录）
     *
     * @return
     */
    @PostMapping("/smsLogin")
    public ResponseEntity smsLogin(@RequestBody Map<String, String> map) {
        String phone = map.get("phone");
        String verificationCode = map.get("verificationCode");
        return adminService.smsLogin(phone, verificationCode);

    }


}

